package com.bm.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bm.server.util.Rutils;
import com.bm.server.vo.R;
import com.bm.server.dao.PingLunDao;
import com.bm.server.entity.Pinglun;
import com.bm.server.service.intf.PingLunService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * YoungMan, may the force be with you.
 *
 * @Author: 吃个小布丁吧
 * @Date: 2022/07/23/10:45
 */
@Service
public class PingLunServiceImpl implements PingLunService {
    @Resource
    private PingLunDao dao;

    @Override
    public R queryByArticleId(int aid) {
        //1.校验
        if(aid>0){
            QueryWrapper<Pinglun> queryWrapper=new QueryWrapper<>();
            queryWrapper.eq("aid",aid);
            queryWrapper.orderByDesc("ctime");
            return Rutils.ok(dao.selectList(queryWrapper));
        }
        return Rutils.fail();
    }

//    @Override
//    public R save(PingLunDto dto, int token) {
//        //1.校验
//        if(dto!=null){
//
//            Pinglun pinglun = new Pinglun();
//            BeanUtils.copyProperties(dto,pinglun);
//           /* comment.setCtime(new Date());
//            comment.setFlag(1);
//            comment.setUid(token);*/
//            pinglun.setUid(token);
//            pinglun.setCtime((new Date()));
//            //3.添加数据到数据库
//            if(dao.insert(pinglun)>0){
//                //更改 积分
//
//                return Rutils.ok();
//            }
//        }
//        return Rutils.fail();
//    }
}
